//
// Created by 谢哲 on 2021/4/23.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;

    vector<int> vdata(n);

    for (int i=0;i<n;++i) cin >> vdata[i];

    for (;m;--m) next_permutation(vdata.begin(), vdata.end());

    for (auto p: vdata) cout << p << " ";

    return 0;
}
